﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Navigation;
using System.Windows.Browser;

namespace EditorialAdministration
{
    public partial class MainPage2 : Page
    {
        public MainPage2()
        {
            this.DataContext = App.CurrentAppState;
            InitializeComponent();           

            this.Loaded += new RoutedEventHandler(MainPage2_Loaded);
        }

        void MainPage2_Loaded(object sender, RoutedEventArgs e)
        {
            // http://localhost:3122/AutomationHomeSite/AutomationAppListPage.aspx
            string url = HtmlPage.Document.DocumentUri.OriginalString.Trim().ToLower();
            if (!url.EndsWith("aspx") || url.EndsWith("default.aspx"))
            {
                _navFrame.Source = new Uri("/MainPage.xaml", UriKind.Relative);
                return;
            }

            int index = url.LastIndexOf("/");
            if (index >= 0)
            {
                string xamlName = url.Substring(index + 1, url.Length - index - 6);
                _navFrame.Source = new Uri("/Admin/Views/" + xamlName + ".xaml", UriKind.Relative);
            }
        }

        // Executes when the user navigates to this page.
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
        }

    }
}
